﻿using Hvam.SharePoint.Search.Query.Site.Models;

namespace Hvam.SharePoint.Search.Query.Site.ResultSteps
{
    internal class SizeResultStep : SiteSearchResultStep
    {
        public SizeResultStep(SiteSearchQuery query) : base(query)
        {
            
        }

        public override SiteSearchResult Process(SiteSearchResult result)
        {
            if (Query.RequestedProperties.Contains("size") && 
                !result.Properties.ContainsKey("size"))
            {
                var item = result.ListItem;

                if (item.File != null)
                {
                    result.Properties.Add("size", item.File.TotalLength.ToString());
                }
            }
            return result;
        }
    }
}
